package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysLmUser;
import com.ruoyi.system.service.ISysLmUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 联盟成员信息Controller
 * 
 * @author ruoyi
 * @date 2023-04-09
 */
@RestController
@RequestMapping("/system/lmuser")
public class SysLmUserController extends BaseController
{
    @Autowired
    private ISysLmUserService sysLmUserService;

    /**
     * 查询联盟成员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:lmuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLmUser sysLmUser)
    {
        startPage();
        List<SysLmUser> list = sysLmUserService.selectSysLmUserList(sysLmUser);
        return getDataTable(list);
    }

    /**
     * 导出联盟成员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:lmuser:export')")
    @Log(title = "联盟成员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLmUser sysLmUser)
    {
        List<SysLmUser> list = sysLmUserService.selectSysLmUserList(sysLmUser);
        ExcelUtil<SysLmUser> util = new ExcelUtil<SysLmUser>(SysLmUser.class);
        util.exportExcel(response, list, "联盟成员信息数据");
    }

    /**
     * 获取联盟成员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:lmuser:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return success(sysLmUserService.selectSysLmUserByUId(uId));
    }

    /**
     * 新增联盟成员信息
     */
    @PreAuthorize("@ss.hasPermi('system:lmuser:add')")
    @Log(title = "联盟成员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLmUser sysLmUser)
    {
        return toAjax(sysLmUserService.insertSysLmUser(sysLmUser));
    }

    /**
     * 修改联盟成员信息
     */
    @PreAuthorize("@ss.hasPermi('system:lmuser:edit')")
    @Log(title = "联盟成员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLmUser sysLmUser)
    {
        return toAjax(sysLmUserService.updateSysLmUser(sysLmUser));
    }

    /**
     * 删除联盟成员信息
     */
    @PreAuthorize("@ss.hasPermi('system:lmuser:remove')")
    @Log(title = "联盟成员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Long[] uIds)
    {
        return toAjax(sysLmUserService.deleteSysLmUserByUIds(uIds));
    }
    
    
    
    
    
    
    
    @Log(title = "联盟成员管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:lmuser:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<SysLmUser> util = new ExcelUtil<SysLmUser>(SysLmUser.class);
        List<SysLmUser> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = sysLmUserService.importUser(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<SysLmUser> util = new ExcelUtil<SysLmUser>(SysLmUser.class);
        util.importTemplateExcel(response, "用户数据");
    }
    
    
    
    
}
